Telegram Group & Telegram Channel
🤝 Как вызвать Python из C — гайд для ресерчеров и хардкорных разработчиков

Если вы пишете код на C и Python, рано или поздно возникнет задача: как вызывать Python из C? Особенно если вы работаете с AI-исследованиями, Tensorflow, или хотите встроить скрипты в уже существующий C-проект.

Вот краткое руководство:

1⃣ Подключить Python.h:
python3-config --includes


2⃣ Включить заголовочный файл в C:

В Cmain.c:
#include <Python.h>


3⃣ Скомпилировать:
gcc Cmain.c -I/usr/include/python3.8 -lpython3.8 -o Cmain.o


4⃣ Инициализировать интерпретатор:
setenv("PYTHONPATH", "./", 1);
Py_Initialize();
// ...
Py_Finalize();


5⃣ Импортировать модуль и вызывать функцию:
PyObject *module = PyImport_ImportModule("PythonFunctions");
PyObject *func = PyObject_GetAttrString(module, "PrintList");
PyObject_CallObject(func, args);


6⃣ Аргументы (списки, числа и пр.):
Создаём через PyList_New, PyLong_FromLong, PyTuple_Pack.

7⃣ Очистка памяти:
Не забываем про Py_XDECREF(...)

▶️ Подойдёт для:
📍Встраивания ML-логики в C
📍Быстрого прототипирования
📍Работы с TensorFlow C API

▶️ Полный гайд и файлы — в детальной статье: https://clc.to/ys3cjw

Библиотека питониста #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/cppproglib/5762
Create:
Last Update:

🤝 Как вызвать Python из C — гайд для ресерчеров и хардкорных разработчиков

Если вы пишете код на C и Python, рано или поздно возникнет задача: как вызывать Python из C? Особенно если вы работаете с AI-исследованиями, Tensorflow, или хотите встроить скрипты в уже существующий C-проект.

Вот краткое руководство:

1⃣ Подключить Python.h:

python3-config --includes


2⃣ Включить заголовочный файл в C:

В Cmain.c:
#include <Python.h>


3⃣ Скомпилировать:
gcc Cmain.c -I/usr/include/python3.8 -lpython3.8 -o Cmain.o


4⃣ Инициализировать интерпретатор:
setenv("PYTHONPATH", "./", 1);
Py_Initialize();
// ...
Py_Finalize();


5⃣ Импортировать модуль и вызывать функцию:
PyObject *module = PyImport_ImportModule("PythonFunctions");
PyObject *func = PyObject_GetAttrString(module, "PrintList");
PyObject_CallObject(func, args);


6⃣ Аргументы (списки, числа и пр.):
Создаём через PyList_New, PyLong_FromLong, PyTuple_Pack.

7⃣ Очистка памяти:
Не забываем про Py_XDECREF(...)

▶️ Подойдёт для:
📍Встраивания ML-логики в C
📍Быстрого прототипирования
📍Работы с TensorFlow C API

▶️ Полный гайд и файлы — в детальной статье: https://clc.to/ys3cjw

Библиотека питониста #буст

BY Библиотека C/C++ разработчика | cpp, boost, qt




Share with your friend now:
tg-me.com/cppproglib/5762

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

Should I buy bitcoin?

“To the extent it is used I fear it’s often for illicit finance. It’s an extremely inefficient way of conducting transactions, and the amount of energy that’s consumed in processing those transactions is staggering,” the former Fed chairwoman said. Yellen’s comments have been cited as a reason for bitcoin’s recent losses. However, Yellen’s assessment of bitcoin as a inefficient medium of exchange is an important point and one that has already been raised in the past by bitcoin bulls. Using a volatile asset in exchange for goods and services makes little sense if the asset can tumble 10% in a day, or surge 80% over the course of a two months as bitcoin has done in 2021, critics argue. To put a finer point on it, over the past 12 months bitcoin has registered 8 corrections, defined as a decline from a recent peak of at least 10% but not more than 20%, and two bear markets, which are defined as falls of 20% or more, according to Dow Jones Market Data.

Newly uncovered hack campaign in Telegram

The campaign, which security firm Check Point has named Rampant Kitten, comprises two main components, one for Windows and the other for Android. Rampant Kitten’s objective is to steal Telegram messages, passwords, and two-factor authentication codes sent by SMS and then also take screenshots and record sounds within earshot of an infected phone, the researchers said in a post published on Friday.

Библиотека C C разработчика | cpp boost qt from ca


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA